package com.boot.controller;


import com.boot.pojo.Headline;
import com.boot.service.HeadlineService;
import com.boot.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("headline")
@CrossOrigin
public class HeadlineController {

    @Autowired
    private HeadlineService headlineService;

    @PostMapping("publish")
    public Result publish(@RequestBody Headline headline, @RequestHeader String token) {
        return headlineService.publish(headline, token);
    }

    @PostMapping("findHeadlineByHid")
    public Result findHeadlineByHid(Integer hid) {
        return headlineService.findHeadlineByHid(hid);
    }

    @PostMapping("update")
    public Result update(@RequestBody Headline headline, @RequestHeader String token) {
        return headlineService.updateByUser(headline, token);
    }

    @PostMapping("delete")
    public Result delete(Integer hid) {
        boolean isDel = headlineService.removeById(hid);
        if (isDel) {
            return Result.ok(null);
        }
        return Result.build(null,509,"数据删除失败");

    }
}
